
package myjme.appstate.plainappstate;

import Globals.AllGlobal;
import Globals.ColorTheme;
import brain.MyBrain;
import com.jme3.app.Application;
import com.jme3.app.SimpleApplication;
import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager;
import com.jme3.asset.AssetManager;
import com.jme3.font.BitmapFont;
import com.jme3.font.BitmapText;
import com.jme3.input.InputManager;
import com.jme3.input.KeyInput;
import com.jme3.input.MouseInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.AnalogListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.input.controls.MouseAxisTrigger;
import com.jme3.input.controls.MouseButtonTrigger;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.renderer.Camera;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Cylinder;
import com.jme3.scene.shape.Line;
import com.jme3.ui.Picture;
import controller.MyController;
import database.operate.OperateMyDatabaseImpl;
import java.awt.BorderLayout;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JLabel;
import model.GongZuoMian_Model;
import model.ZuanChang_Model;
import model.ZuanKong_Model;

/**
 *
 * @author Administrator
 */
public class PlainAppstate extends AbstractAppState{
    private Random r=new Random();
    private SimpleApplication app;
    private Camera cam;
    private Node rootNode;
    private Node guiNode;
    
    //这个是为了调整我们的外形边框的，为了适应画图的准确放置
    private Node xianKuangNode;
    private boolean xianKuangMoveB=false;
    private BitmapText bkydText;
    
    private Node plainContainerNode;
    private AssetManager assetManager;
    private InputManager inputManager;
    private static Box mesh = new Box(Vector3f.ZERO, 2, 2, 2);
    private MyBrain brain;
    private MyController controller;
    private BitmapFont guiFont;
    private float fwjF=0;
    private float sgqsgszbx=0;
    private float sgqsgszby=0;
    private float gzmgszbx=0;
    private float gzmgszby=0;
    private float l=0;
    float diKaErX=0;
    float diKaErY=0;
    float ycjlF=60;
    boolean myMoveB=false;
    
    float screenMoveX=0;
    float screenMoveY=0;
    float scale=0;
    
    //缩放比例，这个是关于倾角的问题
    float QINGJIAOSUOFANGBILIF=1.0f;
    
    @Override
    public void initialize(AppStateManager stateManager, Application app) {
        super.initialize(stateManager, app);
        this.app          = (SimpleApplication) app;
        this.cam          = this.app.getCamera();
        this.rootNode     = this.app.getRootNode();
        this.assetManager = this.app.getAssetManager();
        this.guiNode      = this.app.getGuiNode();
        this.inputManager = this.app.getInputManager();
        
        
               /** Write text on the screen (HUD) */
        
        guiFont = assetManager.loadFont("Interface/mychinese/myfont.fnt");
//        BitmapText helloText = new BitmapText(guiFont, false);
//        helloText.setSize(12);
//        helloText.setText("你好");
//        helloText.setColor(ColorRGBA.Black);
//        helloText.setLocalTranslation(1552, helloText.getLineHeight(), 0);
//        
        plainContainerNode=new Node();
        guiNode.attachChild(plainContainerNode);
//        plainContainerNode.attachChild(helloText);
        bkydText = new BitmapText(guiFont, false);
         /** Map one or more inputs to an action */
        inputManager.addMapping("action move", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
        inputManager.addMapping("Zoom in",new KeyTrigger(KeyInput.KEY_I),new MouseAxisTrigger(MouseInput.AXIS_WHEEL,true));
        inputManager.addMapping("Zoom out",new KeyTrigger(KeyInput.KEY_O),new MouseAxisTrigger(MouseInput.AXIS_WHEEL,false));
        inputManager.addMapping("Move left",new KeyTrigger(KeyInput.KEY_LEFT),new MouseAxisTrigger(MouseInput.AXIS_X, true));
        inputManager.addMapping("Move right",new KeyTrigger(KeyInput.KEY_RIGHT),new MouseAxisTrigger(MouseInput.AXIS_X, false));
        inputManager.addMapping("Move up",new KeyTrigger(KeyInput.KEY_UP),new MouseAxisTrigger(MouseInput.AXIS_Y, false));
        inputManager.addMapping("Move down",new KeyTrigger(KeyInput.KEY_DOWN),new MouseAxisTrigger(MouseInput.AXIS_Y, true));
        inputManager.addMapping("YiDongXianKuang", new KeyTrigger(KeyInput.KEY_M));
        /**Use ActionListener to respond to pressed/released inputs (key presses, mouse clicks) */ 
        ActionListener actionListener=new ActionListener() {

            public void onAction(String name, boolean isPressed, float tpf) {
                
                if(name.equals("action move")&&isPressed){
                    myMoveB=true;
                }
                if(name.equals("action move")&&!isPressed){
                    myMoveB=false;
                }
                if (name.equals("YiDongXianKuang")&&isPressed) {
                    xianKuangMoveB=!xianKuangMoveB;
                    if (xianKuangMoveB) {
                        bkydText.setSize(24);
                    }else{
                        bkydText.setSize(0);
                    }
                }
            }
        };
        
        AnalogListener analogListener=new AnalogListener() {

            public void onAnalog(String name, float value, float tpf) {
                
                if(name.equals("Zoom in")){
                    plainContainerNode.scale(0.9f);
                    plainContainerNode.move(0.01f*screenMoveX, 0.01f*screenMoveY, 0);
                }else if(name.equals("Zoom out")){
                    plainContainerNode.scale(1.1f);
                    plainContainerNode.move(-0.01f*screenMoveX, -0.01f*screenMoveY, 0);
                }else if(name.equals("Move left")&&myMoveB){
                    if (xianKuangMoveB) {
                        xianKuangNode.move(-14f, 0, 0);
                        
                    }else{
                        plainContainerNode.move(-14f, 0, 0);
                        screenMoveX-=14;
                        
                    }
                    
                }else if(name.equals("Move right")&&myMoveB){
                    if (xianKuangMoveB) {
                        xianKuangNode.move(14, 0, 0);
                        
                    }else{
                        plainContainerNode.move(14f, 0, 0);
                        screenMoveX+=14;
                        
                    }
                    
                }else if(name.equals("Move up")&&myMoveB){
                    if (xianKuangMoveB) {
                        xianKuangNode.move(0,14,0);
                        
                    } else {
                        plainContainerNode.move(0,14f, 0);
                        screenMoveY-=14;
                        
                    }
                    
                }else if(name.equals("Move down")&&myMoveB){
                    if (xianKuangMoveB) {
                        xianKuangNode.move(0,-14,0);
                        
                    } else {
                        plainContainerNode.move(0,-14f, 0);
                        screenMoveY+=14;
                        
                    }
                    
                }
            }
        };
        /** Add an action to one or more listeners */
        inputManager.addListener(analogListener, new String[]{"Zoom in","Zoom out","Move left","Move right","Move up","Move down"});
        inputManager.addListener(actionListener, new String[]{"action move","YiDongXianKuang"});
        xianKuangNode=new Node();
        //边框信心初始化
        storeBianKuang();
        //提示，我们的边框是否在移动
        
        bkydText.setSize(0);
        bkydText.setText("边框移动");
        bkydText.setColor(ColorRGBA.Red);
        bkydText.move(300, 47, 0);
        plainContainerNode.attachChild(bkydText);
    }

    @Override
    public void update(float tpf) {
        super.update(tpf); 
    }

    @Override
    public void cleanup() {
        super.cleanup(); 

        while(plainContainerNode.getChildren().size()>0){
            plainContainerNode.getChild(plainContainerNode.getChildren().size()-1).removeFromParent();
        }
    }
    public void drawGrid(int gszbyCount,int gszbxCount){
        fwjF=controller.getFANGWEIJIAO();
        try {
            ArrayList<GongZuoMian_Model> gzmms= OperateMyDatabaseImpl.getAllResult(AllGlobal.GONGZUOMIAN_SQL);
            if(gzmms.size()>0){
                GongZuoMian_Model gzmm=gzmms.get(0);
                this.sgqsgszbx=Float.valueOf(gzmm.getSgqsgszbx());
                this.sgqsgszby=Float.valueOf(gzmm.getSgqsgszby());
            }
           
        } catch (Exception ex) {
            Logger.getLogger(MyController.class.getName()).log(Level.SEVERE, null, ex);
        }
        for(int i=0;i<gszbyCount;i++){
            Geometry linGeo=getLine("line_2d_x"+i,800);
            linGeo.move((i+2)*100, 100, 0);
            plainContainerNode.attachChild(linGeo);            
            linGeo.rotate(0, 0, fwjF*FastMath.DEG_TO_RAD);
            /** Write text on the screen (HUD) */
            guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
            BitmapText helloText = new BitmapText(guiFont, false);
            helloText.setSize(12);
            helloText.setColor(ColorRGBA.Red);
            helloText.setText(sgqsgszby+i*100+"");
            helloText.setLocalTranslation((i+2)*100, 100, 0);
            plainContainerNode.attachChild(helloText);
 
        }
        for(int j=0;j<gszbxCount;j++){
            Geometry linGeo=getLine("line_2d_y"+j,1450);
            linGeo.move(100, (j+2)*100, 0);
            plainContainerNode.attachChild(linGeo);            
            linGeo.rotate(0, 0, (fwjF-90)*FastMath.DEG_TO_RAD);
            /** Write text on the screen (HUD) */
            guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
            BitmapText helloText = new BitmapText(guiFont, false);
            helloText.setSize(12);
            helloText.setColor(ColorRGBA.Red);
            helloText.setText(sgqsgszbx+j*100-(gszbxCount-1)*100+"");
            helloText.setLocalTranslation(100, (j+2)*100, 0);
            plainContainerNode.attachChild(helloText);
        }
    }
    public void drawRoadway(float width,float length){
        try {
            //这里说明一下，那个通过fastmath取得的角度是弧度制的不用再乘以fastmath.deg_...;
            ArrayList<GongZuoMian_Model> gzmms=OperateMyDatabaseImpl.getAllResult(AllGlobal.GONGZUOMIAN_SQL);
            if(gzmms.size()>0){
                GongZuoMian_Model gzmm=gzmms.get(0);
                this.gzmgszbx=Float.parseFloat(gzmm.getGzmgszbX());
                this.gzmgszby=Float.parseFloat(gzmm.getGzmgszbY());
                this.fwjF=Float.parseFloat(gzmm.getGzmfwj());
                this.sgqsgszbx=Float.parseFloat(gzmm.getSgqsgszbx());
                this.sgqsgszby=Float.parseFloat(gzmm.getSgqsgszby());
                this.l=FastMath.
                        sqrt((gzmgszbx-sgqsgszbx+400)*(gzmgszbx-sgqsgszbx+400)+
                        (gzmgszby-sgqsgszby)*(gzmgszby-sgqsgszby));
                float sinCiTa=(gzmgszby-sgqsgszby)/l;
                float ciTa=FastMath.asin(sinCiTa);
                float beiTa=ciTa+(90-fwjF)*FastMath.DEG_TO_RAD;
                diKaErX=l*FastMath.sin(beiTa);
                diKaErY=l*FastMath.cos(beiTa);
                Geometry showPlainGeo=new Geometry("showgeo",mesh);
                Material material=new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
                material.setColor("Color", ColorRGBA.Cyan);
                showPlainGeo.setMaterial(material);
                showPlainGeo.move(diKaErX+200, diKaErY+200, 0);
                plainContainerNode.attachChild(showPlainGeo);
                
                Line shuncaoLine=new Line(Vector3f.ZERO, 
                        new Vector3f(Float.parseFloat(gzmm.getGzmzxcdString())*QINGJIAOSUOFANGBILIF, 0, 0));
                shuncaoLine.setLineWidth(4);
                Geometry jiaoShunGeom=new Geometry("jiaoshun", shuncaoLine);
                Geometry guiShunGeom=new Geometry("guishun", shuncaoLine);
                Material shuncaoMat=new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
                shuncaoMat.setColor("Color", ColorRGBA.Cyan);
                jiaoShunGeom.setMaterial(shuncaoMat);
                guiShunGeom.setMaterial(shuncaoMat);
                jiaoShunGeom.move(diKaErX+200, diKaErY+200, 0);
                guiShunGeom.move(diKaErX+200, diKaErY+200-Float.parseFloat(gzmm.getGzmcd()), 0);
                plainContainerNode.attachChild(jiaoShunGeom);
                plainContainerNode.attachChild(guiShunGeom);
                
                Line gzmLine=new Line(Vector3f.ZERO, new Vector3f(0, -Float.parseFloat(gzmm.getGzmcd()), 0));
                gzmLine.setLineWidth(4);
                Geometry gzmGeom=new Geometry("gzmLine", gzmLine);
                gzmGeom.setMaterial(shuncaoMat);;
                gzmGeom.move(diKaErX+200, diKaErY+200, 0);
                plainContainerNode.attachChild(gzmGeom);
            }
        } catch (Exception ex) {
            Logger.getLogger(PlainAppstate.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    public void drawCore(){
        
    }
    public void drawZC(){
        try {
            ArrayList<ZuanChang_Model> infoList=OperateMyDatabaseImpl.getAllResult(AllGlobal.ZUANCHANG_SQL);
            ZuanChang_Model infoModel=new ZuanChang_Model();
            for(int i=0;i<infoList.size();i++){
                //画线上的长方形
                Node zcCFTNode=new Node();
                Geometry zclineChang1=getLine("chang1", 4.5f, ColorTheme.SMALL_WATER_RGBA);
                Geometry zclineChang2=getLine("chang2", 4.5f, ColorTheme.SMALL_WATER_RGBA);
                Geometry zclineKuan1=getLine("kuan1", 4.5f, ColorTheme.SMALL_WATER_RGBA);
                Geometry zclineKuan2=getLine("kuan2", 4.5f, ColorTheme.SMALL_WATER_RGBA);
                zclineChang1.move(0, 4.5f, 0);
                zclineKuan1.rotate(0, 0, 90*FastMath.DEG_TO_RAD);
                zclineKuan2.rotate(0, 0, 90*FastMath.DEG_TO_RAD);
                zclineKuan2.move(4.5f, 0, 0);
                zcCFTNode.attachChild(zclineChang1);
                zcCFTNode.attachChild(zclineChang2);
                zcCFTNode.attachChild(zclineKuan1);
                zcCFTNode.attachChild(zclineKuan2);
                //这里是画钻场文字的
                guiFont = assetManager.loadFont("Interface/mychinese/myfont.fnt");
                BitmapText helloText = new BitmapText(guiFont, false);
                helloText.setSize(8);
                helloText.setColor(ColorRGBA.Red);
                helloText.move(0, 5, 0);
                zcCFTNode.attachChild(helloText);
                //矫正移动
                zcCFTNode.move(-2,-2,0);
                //笛卡尔移动
                zcCFTNode.move(diKaErX+200, diKaErY+200, 0);
                    //钻场型移动
                if(infoList.get(i)!=null){
                        ZuanChang_Model zuanChang_Model=infoList.get(i);
                        helloText.setText(zuanChang_Model.getMingcheng());
                    if(controller.getGZM_TYPE()==AllGlobal.GZM_TYPE_LEFT){

                            zcCFTNode.move(Float.parseFloat(zuanChang_Model.getXdzby()),
                                    -Float.parseFloat(zuanChang_Model.getXdzbx()), 
                                    0);
                     }else if(controller.getGZM_TYPE()==AllGlobal.GZM_TYPE_RIGHT){

                            zcCFTNode.move(controller.getGzmzxcd()-Float.parseFloat(zuanChang_Model.getXdzby()),
                                    -Float.parseFloat(zuanChang_Model.getXdzbx()), 
                                    0);
                     }
                 }
                plainContainerNode.attachChild(zcCFTNode);
            }
            
        } catch (Exception ex) { 
            Logger.getLogger(PlainAppstate.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    public void drawSGT() throws Exception{
        
        ArrayList<ZuanChang_Model> infoList=OperateMyDatabaseImpl.getAllResult(AllGlobal.ZUANCHANG_SQL);
        ZuanChang_Model infoModel=new ZuanChang_Model();
        if(!infoList.isEmpty()){
            infoModel=infoList.get(0);
        }else{
            infoModel.setKongxilvString("0.4");
        }
        float zyF=controller.getZhongyajixian();
        Material drillMat=new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        drillMat.setColor("Color", ColorRGBA.Black);
        ArrayList<ZuanKong_Model> zkms=OperateMyDatabaseImpl.getAllResult(AllGlobal.ZUANKONG_SQL);
        Iterator<ZuanKong_Model> zIt=zkms.iterator();
        
        while(zIt.hasNext()){
            ZuanKong_Model zkm=zIt.next();
            Float ckFloat=Float.parseFloat(zkm.getChengkong());
            ColorRGBA colorRGBA;
            if(ckFloat<30){
                colorRGBA=ColorTheme.SMALL_WATER_RGBA;
            }else if(ckFloat<60){
                colorRGBA=ColorTheme.MIDDLE_WATER_RGBA;
            }else if(ckFloat<90){
                colorRGBA=ColorTheme.BIG_WATER_RGBA;
            }else if(ckFloat>=90){
                colorRGBA=ColorTheme.BIGGEST_WATER_RGBA;
            }else{
                colorRGBA=ColorTheme.OTHER_WATER_RGBA;
            }
            //这里是画钻孔文字的
            guiFont = assetManager.loadFont("Interface/mychinese/myfont.fnt");
            BitmapText helloText = new BitmapText(guiFont, false);
            helloText.setSize(8);
            helloText.setText(zkm.getMingcheng());
            helloText.setColor(ColorRGBA.Red);
            helloText.move(80, 5, 0);
            
            Node allNode=new Node();
            Geometry myLineGeometry=getLine("hahatest", 
                    Float.parseFloat(zkm.getKongshen())*FastMath.cos(FastMath.DEG_TO_RAD*Float.parseFloat(zkm.getQingjiao())), 
                    colorRGBA);
            
            //画线上的长方形
            Geometry lineChang1=getLine("chang1", 12, colorRGBA);
            Geometry lineChang2=getLine("chang2", 12, colorRGBA);
            Geometry lineKuan1=getLine("kuan1", 4, colorRGBA);
            Geometry lineKuan2=getLine("kuan2", 4, colorRGBA);
            //移动长方体
            lineChang1.move(0, 4, 0);
            lineKuan1.rotate(0, 0, 90*FastMath.DEG_TO_RAD);
            lineKuan2.rotate(0, 0, 90*FastMath.DEG_TO_RAD);
            lineKuan2.move(12, 0, 0);
            Node cftNode=new Node();
            cftNode.attachChild(lineChang1);
            cftNode.attachChild(lineChang2);
            cftNode.attachChild(lineKuan1);
            cftNode.attachChild(lineKuan2);
            cftNode.move(55, -2, 0);
            Float ckF=Float.parseFloat(zkm.getChengkong());
            Picture tulitest=new Picture("tulitte");
            if(ckF<30){
                tulitest.setImage(assetManager, "Interface/shuidi/1.jpg", false);
            }else if(ckF<60){
                tulitest.setImage(assetManager, "Interface/shuidi/2.jpg", false);
            }else if(ckF<90){
                tulitest.setImage(assetManager, "Interface/shuidi/3.jpg", false);
            }else if(ckF>=90){
                tulitest.setImage(assetManager, "Interface/shuidi/4.jpg", false);
            }else{
                tulitest.setImage(assetManager, "Interface/shuidi/5.jpg", false);
            }
            
            tulitest.move(-5, -5, -5);
            tulitest.setWidth(5);
            tulitest.setHeight(10);
            tulitest.move(Float.parseFloat(zkm.getChushuidianshuipingtouying()), 0, 0);
            allNode.attachChild(helloText);
            allNode.attachChild(myLineGeometry);
            allNode.attachChild(tulitest);
            allNode.attachChild(cftNode);
            //笛卡尔移动
            allNode.move(diKaErX+200, diKaErY+200, 0);
            //钻场型移动
            ArrayList<ZuanChang_Model> alist=OperateMyDatabaseImpl.getOne(AllGlobal.ZUANCHANG_SQL, 
                        "select * from zuanchang where mingcheng='"+zkm.getZuanchang()+"';");
            if(!alist.isEmpty()){
                ZuanChang_Model zuanChang_Model=alist.get(0);
                if(controller.getGZM_TYPE()==AllGlobal.GZM_TYPE_LEFT){

                    allNode.move(Float.parseFloat(zuanChang_Model.getXdzby())*QINGJIAOSUOFANGBILIF,
                            -Float.parseFloat(zuanChang_Model.getXdzbx()), 
                            0);
//                    cg2dKX.move(Float.parseFloat(zuanChang_Model.getXdzby()),
//                            -Float.parseFloat(zuanChang_Model.getXdzbx()), 
//                            0);
                }else if(controller.getGZM_TYPE()==AllGlobal.GZM_TYPE_RIGHT){

                    allNode.move((controller.getGzmzxcd()-Float.parseFloat(zuanChang_Model.getXdzby()))*QINGJIAOSUOFANGBILIF,
                            -Float.parseFloat(zuanChang_Model.getXdzbx()), 
                            0);
                }
            } 
            float ciTa=controller.getFANGWEIJIAO()-Float.parseFloat(zkm.getFangwei());
            allNode.rotate(0, 0, FastMath.DEG_TO_RAD*ciTa);
            plainContainerNode.attachChild(allNode);
            
        }
    }
    public void drawDrill(float ycjl) throws Exception{
        ArrayList<ZuanChang_Model> infoList=OperateMyDatabaseImpl.getAllResult(AllGlobal.ZUANCHANG_SQL);
        ZuanChang_Model infoModel=new ZuanChang_Model();
        if(!infoList.isEmpty()){
            infoModel=infoList.get(0);
        }else{
            infoModel.setKongxilvString("0.4");
        }
        float zyF=controller.getZhongyajixian();
        Material drillMat=new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        drillMat.setColor("Color", ColorRGBA.Black);
        ArrayList<ZuanKong_Model> zkms=OperateMyDatabaseImpl.getAllResult(AllGlobal.ZUANKONG_SQL);
        Iterator<ZuanKong_Model> zIt=zkms.iterator();
        while(zIt.hasNext()){
            ZuanKong_Model zkm=zIt.next();
            float rF=brain.CaculateR(Float.parseFloat(zkm.getKongshen())-20, Float.parseFloat(infoModel.getKongxilvString()), 1, 
                        Float.parseFloat(zkm.getVa())+Float.parseFloat(zkm.getVb())+Float.parseFloat(zkm.getVc())
                        , AllGlobal.CYLINDER_TYPE);                
            float longRf=(rF/Math.abs(FastMath.sin(FastMath.DEG_TO_RAD*Float.parseFloat(zkm.getQingjiao()))));
            MyJMECircle ellipse=new MyJMECircle(longRf, rF);
            Geometry cg2d=new Geometry(zkm.getMingcheng()+"2D", ellipse); 
            cg2d.rotate(0,0,FastMath.DEG_TO_RAD*(fwjF-Float.parseFloat(zkm.getFangwei())));
            Material drillMatRand=new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
           
            
            cg2d.scale(5);
            //画孔芯
            Cylinder cylinderKX=new Cylinder(16,16, 0.25f, 1,true);
            Geometry cg2dKX=new Geometry(zkm.getMingcheng()+"2D"+"kongxin", cylinderKX); 
            cg2dKX.rotate(0,0,FastMath.DEG_TO_RAD*(fwjF-Float.parseFloat(zkm.getFangwei())));
            Material drillMatRandKX=new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
            if(Float.parseFloat(zkm.getZhujiangqian())<30){
                drillMatRandKX.setColor("Color", ColorTheme.SMALL_WATER_RGBA);
                drillMatRand.setColor("Color", ColorTheme.SMALL_WATER_RGBA);
            }
            else if(Float.parseFloat(zkm.getZhujiangqian())<60){
                drillMatRandKX.setColor("Color", ColorTheme.MIDDLE_WATER_RGBA);
                drillMatRand.setColor("Color", ColorTheme.MIDDLE_WATER_RGBA);
            }
            else if(Float.parseFloat(zkm.getZhujiangqian())<90){
                drillMatRandKX.setColor("Color", ColorTheme.BIG_WATER_RGBA);
                drillMatRand.setColor("Color", ColorTheme.BIG_WATER_RGBA);
            }
            else if(Float.parseFloat(zkm.getZhujiangqian())>=90){
                drillMatRandKX.setColor("Color", ColorTheme.BIGGEST_WATER_RGBA);
                drillMatRand.setColor("Color", ColorTheme.BIGGEST_WATER_RGBA);
            }else{
                drillMatRandKX.setColor("Color", ColorTheme.OTHER_WATER_RGBA);
                drillMatRand.setColor("Color", ColorTheme.OTHER_WATER_RGBA);
            }
            cg2dKX.setMaterial(drillMatRandKX); 
            cg2d.setMaterial(drillMatRand);//设置钻孔
            cg2dKX.scale(5);
            //笛卡尔移动
            cg2d.move(diKaErX+200, diKaErY+200, 0);
            cg2dKX.move(diKaErX+200, diKaErY+200, 0);
            //钻场型移动
            ArrayList<ZuanChang_Model> alist=OperateMyDatabaseImpl.getOne(AllGlobal.ZUANCHANG_SQL, 
                        "select * from zuanchang where mingcheng='"+zkm.getZuanchang()+"';");
            if(!alist.isEmpty()){
                ZuanChang_Model zuanChang_Model=alist.get(0);
                if(controller.getGZM_TYPE()==AllGlobal.GZM_TYPE_LEFT){

                    cg2d.move(Float.parseFloat(zuanChang_Model.getXdzby())*QINGJIAOSUOFANGBILIF,
                            -Float.parseFloat(zuanChang_Model.getXdzbx()), 
                            0);
                    cg2dKX.move(Float.parseFloat(zuanChang_Model.getXdzby())*QINGJIAOSUOFANGBILIF,
                            -Float.parseFloat(zuanChang_Model.getXdzbx()), 
                            0);
                }else if(controller.getGZM_TYPE()==AllGlobal.GZM_TYPE_RIGHT){

                    cg2d.move(controller.getGzmzxcd()-Float.parseFloat(zuanChang_Model.getXdzby())*QINGJIAOSUOFANGBILIF,
                            -Float.parseFloat(zuanChang_Model.getXdzbx()), 
                            0);
                    cg2dKX.move(controller.getGzmzxcd()-Float.parseFloat(zuanChang_Model.getXdzby())*QINGJIAOSUOFANGBILIF,
                            -Float.parseFloat(zuanChang_Model.getXdzbx()), 
                            0);
                }
            } 
            //偏转型移动
            float shuipingL=ycjl/FastMath.tan(Float.parseFloat(zkm.getQingjiao())*FastMath.DEG_TO_RAD);
            float ciTa=controller.getFANGWEIJIAO()-Float.parseFloat(zkm.getFangwei());
            float pzY=shuipingL*FastMath.sin(ciTa*FastMath.DEG_TO_RAD);
            float pzX=shuipingL*FastMath.cos(ciTa*FastMath.DEG_TO_RAD);
            cg2d.move(pzX, pzY, 0);
            cg2dKX.move(pzX, pzY, 0);
            plainContainerNode.attachChild(cg2d);
            plainContainerNode.attachChild(cg2dKX);
            
        }
    }
    /**
     * 下面是绘制孔芯
     * 
     * 
     **/
    
    public Geometry drawCircle(float r){
        return null;
    }
    public void drawAll(){
        QINGJIAOSUOFANGBILIF=FastMath.cos(controller.getMEICENGQINGJIAOF()*FastMath.DEG_TO_RAD);
        plainContainerNode.attachChild(xianKuangNode);
        plainContainerNode.attachChild(bkydText);
        try {
//            guiFont = assetManager.loadFont("Interface/mychinese/myfont.fnt");
//            BitmapText helloText = new BitmapText(guiFont, false);
//            helloText.setSize(guiFont.getCharSet().getRenderedSize());
//            helloText.setText("我是2D显示");
//            helloText.setColor(new ColorRGBA(0.75f, 0.45f, 0.78f, 0.78f));
//            helloText.setLocalTranslation(300, 300, 0);
//            plainContainerNode.attachChild(helloText);
            drawGrid(13, 5);
            drawRoadway(0, 0);
//            drawDrill();
            drawSGT();
            drawBorder();
            testShiGongTu();
        } catch (Exception ex) {
            Logger.getLogger(PlainAppstate.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    public void addController(MyController controller){
        this.controller=controller;
        fwjF=this.controller.getFANGWEIJIAO();
    }
    public void addBrain(MyBrain brain){
        this.brain=brain;
    }
    public Geometry getLine(String name,int length){
        Line line=new Line(Vector3f.ZERO, new Vector3f(length, 0, 0));
        Geometry lineGeo=new Geometry(name,line);
        Material material=new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        material.setColor("Color", ColorRGBA.Blue);
        lineGeo.setMaterial(material);
        return lineGeo;
    }
    public Geometry getLine(String name,float length,ColorRGBA colorRGBA){
        Line line=new Line(Vector3f.ZERO, new Vector3f(length, 0, 0));
        Geometry lineGeo=new Geometry(name,line);
        Material material=new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        material.setColor("Color", colorRGBA);
        lineGeo.setMaterial(material);
        return lineGeo;
    }
    //边框全部储存
    public void storeBianKuang(){
        //最上层边框与最下层边框，内外均包含
        Geometry x_w=getLine("x_w", 1800, ColorRGBA.Black);
        Geometry x_n=getLine("x_n", 1780, ColorRGBA.Black);
        Geometry s_w=getLine("s_w", 1800, ColorRGBA.Black);
        Geometry s_n=getLine("s_n", 1780, ColorRGBA.Black);
        //左右边框包含内外  注意都做了减少40的处理
        Geometry z_w=getLine("z_w", 1058-100, ColorRGBA.Black);
        Geometry z_n=getLine("z_n", 1038-100, ColorRGBA.Black);
        Geometry y_w=getLine("y_w", 1058-100, ColorRGBA.Black);
        Geometry y_n=getLine("y_n", 1038-100, ColorRGBA.Black);
        //绘制动作
        x_w.setLocalTranslation(0, 0, 0);
        x_n.setLocalTranslation(10, 10, 0);
        s_w.setLocalTranslation(0, 1058-100, 0);
        s_n.setLocalTranslation(10, 1048-100, 0);
        z_w.rotate(0, 0, 90*FastMath.DEG_TO_RAD);
        z_n.rotate(0, 0, 90*FastMath.DEG_TO_RAD);
        y_w.rotate(0, 0, 90*FastMath.DEG_TO_RAD);
        y_n.rotate(0, 0, 90*FastMath.DEG_TO_RAD);
        z_w.move(0, 0, 0);
        z_n.move(10,10,0);
        y_w.move(1800,0,0);
        y_n.move(1790, 10, 0);
        //装载内容
        xianKuangNode.attachChild(x_w);
        xianKuangNode.attachChild(x_n);
        xianKuangNode.attachChild(s_w);
        xianKuangNode.attachChild(s_n);
        xianKuangNode.attachChild(z_w);
        xianKuangNode.attachChild(z_n);
        xianKuangNode.attachChild(y_w);
        xianKuangNode.attachChild(y_n);
        
        //下面是内容边框了，内容左
        Geometry n_z_s=getLine("n_z_s", 928, ColorRGBA.Black);
        Geometry n_z_y=getLine("n_z_y", 72, ColorRGBA.Black);
        //绘制动作
        n_z_s.setLocalTranslation(10, 82, 0);
        n_z_y.rotate(0, 0, 90*FastMath.DEG_TO_RAD);
        n_z_y.setLocalTranslation(938, 10, 0);
        //装载内容
        xianKuangNode.attachChild(n_z_y);
        xianKuangNode.attachChild(n_z_s);
        
        //下面内容右
        Geometry n_y_s=getLine("n_y_s", 238, ColorRGBA.Black);
        Geometry n_y_z=getLine("n_y_z", 127, ColorRGBA.Black);
        Geometry n_y_1=getLine("n_y_1", 238, ColorRGBA.Black);
        Geometry n_y_2=getLine("n_y_2", 238, ColorRGBA.Black);
        Geometry n_y_3=getLine("n_y_3", 238, ColorRGBA.Black);
        Geometry n_y_4=getLine("n_y_4", 238, ColorRGBA.Black); 
        Geometry n_y_sx_1=getLine("n_y_sx_1", 68, ColorRGBA.Black);
        Geometry n_y_sx_2=getLine("n_y_sx_2", 68, ColorRGBA.Black);
        Geometry n_y_sx_3=getLine("n_y_sx_3", 68, ColorRGBA.Black);       
        //绘制动作
        n_y_s.setLocalTranslation(1552, 137, 0);
        n_y_z.rotate(0, 0, 90*FastMath.DEG_TO_RAD);
        n_y_z.setLocalTranslation(1552, 10, 0);
        n_y_1.setLocalTranslation(1552, 78, 0);
        n_y_2.setLocalTranslation(1552, 61, 0);
        n_y_3.setLocalTranslation(1552, 44, 0);
        n_y_4.setLocalTranslation(1552, 27, 0);
        n_y_sx_1.rotate(0, 0, 90*FastMath.DEG_TO_RAD);
        n_y_sx_2.rotate(0, 0, 90*FastMath.DEG_TO_RAD);
        n_y_sx_3.rotate(0, 0, 90*FastMath.DEG_TO_RAD);
        n_y_sx_1.move(1611, 10, 0);
        n_y_sx_2.move(1671, 10, 0);
        n_y_sx_3.move(1730, 10, 0);
        //装载内容
        xianKuangNode.attachChild(n_y_4);
        xianKuangNode.attachChild(n_y_3);
        xianKuangNode.attachChild(n_y_2);
        xianKuangNode.attachChild(n_y_1);
        xianKuangNode.attachChild(n_y_z);
        xianKuangNode.attachChild(n_y_s);
        xianKuangNode.attachChild(n_y_sx_1);
        xianKuangNode.attachChild(n_y_sx_2);
        xianKuangNode.attachChild(n_y_sx_3);
        
        //添加图例
        Picture tuli=new Picture("tuli");
        tuli.setImage(assetManager, "Interface/tuli/qingxituli.png", false);
        tuli.move(39, 11, 0);
        tuli.setWidth(819);
        tuli.setHeight(69);
        xianKuangNode.attachChild(tuli);
        
        //添加文字，制图、校对、科长、总工程师、制图日期、比例尺、编号
        guiFont=assetManager.loadFont("Interface/mychinese/myfont.fnt");
        BitmapText zhituText = new BitmapText(guiFont, false);
        zhituText.setSize(14); 
        zhituText.setText("制       图");
        zhituText.setColor(ColorRGBA.Black);
        zhituText.move(1556, 61+17, 0);
        xianKuangNode.attachChild(zhituText);
        BitmapText jiaoduiText = new BitmapText(guiFont, false);
        jiaoduiText.setSize(14);
        jiaoduiText.setText("校       对");
        jiaoduiText.setColor(ColorRGBA.Black);
        jiaoduiText.move(1556, 44+17, 0);
        xianKuangNode.attachChild(jiaoduiText);
        BitmapText kezhangText = new BitmapText(guiFont, false);
        kezhangText.setSize(14);
        kezhangText.setText("科       长");
        kezhangText.setColor(ColorRGBA.Black);
        kezhangText.move(1556, 27+17, 0);
        xianKuangNode.attachChild(kezhangText);
        BitmapText zonggongText = new BitmapText(guiFont, false);
        zonggongText.setSize(14);
        zonggongText.setText("总工程师");
        zonggongText.setColor(ColorRGBA.Black);
        zonggongText.move(1556, 10+17, 0);
        xianKuangNode.attachChild(zonggongText);
        BitmapText riqiText = new BitmapText(guiFont, false);
        riqiText.setSize(14);
        riqiText.setText("制图日期");
        riqiText.setColor(ColorRGBA.Black);
        riqiText.move(1556+119, 61+17, 0);
        xianKuangNode.attachChild(riqiText);
        BitmapText bilichiText = new BitmapText(guiFont, false);
        bilichiText.setSize(14);
        bilichiText.setText("比  例  尺");
        bilichiText.setColor(ColorRGBA.Black);
        bilichiText.move(1556+119, 44+17, 0);
        xianKuangNode.attachChild(bilichiText);
        BitmapText bianhaoText = new BitmapText(guiFont, false);
        bianhaoText.setSize(14);
        bianhaoText.setText("编       号");
        bianhaoText.setColor(ColorRGBA.Black);
        bianhaoText.move(1556+119, 27+17, 0);
        xianKuangNode.attachChild(bianhaoText);
    }
    public void drawBorder(){
        
        
        
        
        
    }
    public AbstractAppState setSD(int sjType,float ycjlF){
        cleanup();
        QINGJIAOSUOFANGBILIF=FastMath.cos(controller.getMEICENGQINGJIAOF()*FastMath.DEG_TO_RAD);
        plainContainerNode.attachChild(xianKuangNode);
        plainContainerNode.attachChild(bkydText);
        if(sjType==AllGlobal.TOUYINGTU){
            //这里是投影设计图
            try {
//            guiFont = assetManager.loadFont("Interface/mychinese/myfont.fnt");
//            BitmapText helloText = new BitmapText(guiFont, false);
//            helloText.setSize(guiFont.getCharSet().getRenderedSize());
//            helloText.setText("我是2D显示");
//            helloText.setColor(new ColorRGBA(0.75f, 0.45f, 0.78f, 0.78f));
//            helloText.setLocalTranslation(300, 300, 0);
//            plainContainerNode.attachChild(helloText);
                drawGrid(13, 5);
                drawRoadway(0, 0);
                drawDrill(ycjlF);
                drawBorder();
            } catch (Exception ex) {
                Logger.getLogger(PlainAppstate.class.getName()).log(Level.SEVERE, null, ex);
                JFrame frame=new JFrame();
                frame.setSize(45,44);
                frame.setLocationRelativeTo(null);
                frame.add(new JLabel("信息提示"), BorderLayout.CENTER);
                frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                frame.setResizable(false);
                frame.setVisible(true);
                return this;
            }
        }else{
            //这里是设计图方法
            try {
//            guiFont = assetManager.loadFont("Interface/mychinese/myfont.fnt");
//            BitmapText helloText = new BitmapText(guiFont, false);
//            helloText.setSize(guiFont.getCharSet().getRenderedSize());
//            helloText.setText("我是2D显示");
//            helloText.setColor(new ColorRGBA(0.75f, 0.45f, 0.78f, 0.78f));
//            helloText.setLocalTranslation(300, 300, 0);
//            plainContainerNode.attachChild(helloText);
                drawGrid(13, 5);
                drawRoadway(0, 0);
                drawSGT();
                drawZC();
                drawBorder();
            } catch (Exception ex) {
                Logger.getLogger(PlainAppstate.class.getName()).log(Level.SEVERE, null, ex);
                JFrame frame=new JFrame();
                frame.setSize(45,44);
                frame.setLocationRelativeTo(null);
                frame.add(new JLabel("信息提示"), BorderLayout.CENTER);
                frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                frame.setResizable(false);
                frame.setVisible(true);
                return this;
            }
        }
        return this;
    }
    //测试外部调用
    public AbstractAppState printme(){
        System.out.println("asd");
        plainContainerNode.rotate(0, 0, 30*FastMath.DEG_TO_RAD);
        return this;
    }
    //下面是测试画施工图
    public void testShiGongTu(){
        
            Node allNode=new Node();
            Geometry myLineGeometry=getLine("hahatest", 189, ColorRGBA.Black);
            
            Picture tulitest=new Picture("tulitte");
            tulitest.setImage(assetManager, "Interface/shuidi/shuidi2.jpg", false);
            tulitest.move(-5, -5, 0);
            tulitest.setWidth(5);
            tulitest.setHeight(10);
            
            //移动到出水点位置
            tulitest.move(88,0,0);
            allNode.attachChild(myLineGeometry);
            allNode.attachChild(tulitest);
            //笛卡尔移动
            allNode.move(diKaErX+200, diKaErY+200, 0);
            //钻场型移动


                    allNode.move(300,
                            300, 
                            0);
                
             allNode.rotate(0, 0, 21*FastMath.DEG_TO_RAD);
            //偏转型移动
            
            plainContainerNode.attachChild(allNode);
            
        
    }
}
